package com.glodon.paas.job.agent.worker;

import java.io.IOException;
import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class KillWorkerTask extends TimerTask {
	private String cmd;
	private Thread cancelThread;
	private static final Logger logger = LoggerFactory.getLogger(WorkerTimeoutTask.class);
	public KillWorkerTask(Thread canThread, String cmd) {
		this.cancelThread = canThread;
		this.cmd = cmd;
	}

	@Override
	public void run() {
		Runtime runtime = Runtime.getRuntime();
		try {
			logger.info("Start to kill task.");
			cancelThread.interrupt();
			runtime.exec("taskkill /F /T /im "+cmd, null);
			logger.info("Task killed sucess.");
		} catch (IOException e) {
			logger.info("Kill task failed.");
		}
	}

}
